<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>ws client</title>
</head>
<body>
<p id="talkMsg" style="border: 1px solid black;width: 600px;height: 800px;margin-left: 5px">
</p>
<input id="message" style="margin-left: 5px"/><button id="sendBtn" onclick="sendMsg()">发送</button>
</body>
<script>
    let ws = new WebSocket("ws://localhost:8080/myWs1")
    ws.onopen=function (){
        // ws.send("hello world!")
    }

    ws.onmessage=function (message){
        console.log('>>> ', message)
        let ele = document.getElementById("talkMsg");
        ele.innerHTML = message.data;
    }

    function sendMsg(){
        let ele = document.getElementById("message");
        let msg = ele.value;
        ws.send(msg)
        ele.value = ''
    }
</script>

</html>